package com.itheima.tlias.controller;

import com.itheima.tlias.anno.Log;
import com.itheima.tlias.pojo.Emp;
import com.itheima.tlias.pojo.PageBean;
import com.itheima.tlias.pojo.Result;
import com.itheima.tlias.servies.EmpServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpServices empServices;


    @GetMapping
    public Result SelectE(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String name, Short gender,
                          @DateTimeFormat(pattern="yyyy-mm-dd")LocalDate begin,
                          @DateTimeFormat(pattern="yyyy-mm-dd")LocalDate end){
        log.info("查询员工数据{},{}",page,pageSize);
        PageBean pageBean = empServices.list(page,pageSize,name,gender,begin,end);
        return Result.success(pageBean);
    }
    @Log
    @DeleteMapping("/{ids}")
    public Result Delete(@PathVariable List<Integer> ids){
        empServices.delete(ids);
        log.info("删除数据中{}",ids);
        return Result.success();
    }
    @Log
    @PostMapping
    public Result Insert(@RequestBody Emp emp){
        empServices.insert(emp);
        log.info("新增员工{}",emp);
        return Result.success();
    }
    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据ID查询员工信息,id{}",id);
        Emp emp = empServices.getById(id);
        return Result.success(emp);
    }
    @Log
    @PutMapping
    public Result update(@RequestBody Emp emp){
        empServices.update(emp);
        log.info("更新员工信息:{}",emp);
        return Result.success();

    }

    @GetMapping("{id}")
    public Result geadatById(@PathVariable Integer id){
        log.info("根据ID查询员工信息,id{}",id);
        Emp emp = empServices.getById(id);
        return Result.success(emp);
    }

    public Result Update(@RequestBody Emp emp) {
        empServices.update(emp);
        log.info("更新员工信息:{}", emp);
        return Result.success();
    }

    public Result Uptdaaaaaaaaaaaaae(@RequestBody Emp emp) {
        empServices.update(emp);
        log.info("更新员工信息:{}", emp);
        return Result.success();
    }

    public Result te(@RequestBody Emp emp) {
        empServices.update(emp);
        log.info("更新员工信息:{}", emp);
        return Result.success();
    }

}
